/**
 * ==========================
 *        【黯然销魂掌】
 *         绝招：黯然
 * ==========================
 */
const RSE = require('../../../common/base-role');
const SVE = require('../../../common/base-tool');
// const COMBAT_D = require('../../../common/combat-d')

class Anran{
    constructor(me, target, jsonData, level) {
        this.me = me;
        this.target = target;
        this.jsonData = jsonData;
        this.level = level;
    }
    
    attack() {
        const me = this.me;
        let target = this.target;
        let lvl, i;

        // 获取技能等级
        lvl = me.special['anran-zhang']*2;

        // 确认目标
        // if( !target ) target = RSE.offensive_target(me);

        if( !target || !me.is_fighting ) return "「黯然销魂」只能在战斗中使用。\n";
        if( Object.keys(me.weapon).length>0 && me.weapon.skill_type!='strike' ) return "你拿着武器怎么能使用「黯然销魂」！\n";
        if( me.special['anran-zhang'] < 150 ) return "你的黯然销魂掌还不够娴熟，使不出「黯然销魂」绝技。\n";
        if( me.special["yunv-xinjing"] < 150 ) return "你的玉女心经等级还不够，使不出「黯然销魂」绝技。\n";
        if (me.mapped.strike.name!="anran-zhang" || me.mapped.parry.name!="anran-zhang" ||
            me.mapped.force.name!="yunv-xinjing" || me.prepared["strike"] != "anran-zhang") return "你现在无法使用「黯然销魂」绝技！!!!!!!!!!!!!\n";
        if(me.isuse.xinjing) return "你正在使用「心经」字诀。\n";
        if(me.max_neili < me.basic.force+lvl+100 ) return "你现在内力太弱，使不出「黯然销魂」。\n";
        if(me.eff_qi >= me.max_qi) return "你现在心情很好，怎么使得出「黯然销魂」绝技。\n";
        if(me.neili < me.force+lvl) return "你现在真气太弱，使不出「黯然销魂」绝技。\n";
        if(me.isuse.xiaohun) return "你现在正在使用「消魂」绝技。\n";
        if(me.qi == 0 ) return "你现在死亡，无法使用「黯然销魂」绝技。\n";
        // 触发技能
        me.isuse['anran'] = 2;
        // i = me.max_qi / me.eff_qi;
        // if( i > 3 ) i = 3;
        // if( i < 1 ) i = 1;
        //
        // let lvl2 = Math.round(lvl/2);
        // let lvl3 = Math.round(lvl/3);
        // if( i > 1 ){
        //     me.temp.strength = lvl3;
        //     me.temp.hurt = 1;
        // }
        // me.temp.damage = lvl2;
        // me.temp.strike = lvl2;
        // me.temp.must_be_hit = 1;
        //
        // COMBAT_D.do_attack(me, target, me.weapon, i, this.jsonData, this.level);
        //
        // me.temp.damage -= lvl2;
        // me.temp.strike -= lvl2;

        if( me.hurt ){
           me.temp.strength -= lvl3;
           delete me.temp.hurt;
        }
        me.neili -= me.basic.force + SVE.random(10, lvl);
        me.jingli -= 50;
        delete me.temp.anran;
        me.start.perform = "黯然销魂 - 黯然";
        delete me.temp.must_be_hit;
        me.start.busy = 1+SVE.random(0,2);

        return SVE.random(1,3);
    }

    perform_name () { return "HIB黯然NOR" }
}

module.exports = Anran;
